<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/27
 * Time: 16:55
 */
//获取前端返回的数据
$name = $_REQUEST['namesa'];
$phone = $_REQUEST['phone'];
$emile = $_REQUEST['emile'];
$wx = $_REQUEST['wx'];
$comply = $_REQUEST['comply'];
$text = $_REQUEST['text'];
//连接数据库
$link=mysqli_connect('localhost','ni','123456')or die(json_encode(array('result'=>'connect database fail!')));
//选择要操作的库
mysqli_select_db($link,'ajaxdb')or die(json_encode(array('result'=>'select database error')));
//定义查询的sql语句
$sql_select="select wx from liuyan where username = '$wx'";
//执行sql，返回结果集
$res=mysqli_query($link,$sql_select);
//根据返回结果判断该用户名是否被注册
if ($wx==''){
    echo json_encode(array('result'=>'namesa dose not allowed null'));
}else{
    if (mysqli_fetch_assoc($res)!=null){
        echo json_encode(array('result'=>'namesa is exist','name'=>$name));
    }else{
        $sql_insert="insert into liuyan(namesa,phone,emile,wx,text,comply)values ('$name','$phone','$emile','$wx','$text','$comply')";
        mysqli_query($link,$sql_insert);
        if (mysqli_affected_rows($link)>0){
            echo json_encode(array('result'=>'success','namesa'=>$name));
        }else{
            echo json_encode(array('result'=>'insert database fail'));
        }
    }
}

//    关闭数据库连接
mysqli_close($link);